﻿Option Explicit On
Option Strict On

Imports ACOMDirector.Framework.Configuration

Namespace Configuration

    Friend Class ACOMConfiguration

#Region " Private Members "

        Private m_Config As XmlConfigSource
        Private m_ThisConfig As IConfig

#End Region

#Region " Constructor "

        ''' <summary>
        ''' Constructor
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New(ByVal Config As XmlConfigSource)
            If Config Is Nothing Then
                Throw New ArgumentNullException("Config")
            End If

            m_Config = Config

            m_ThisConfig = Config.Configs.Item("ACOMConfiguration")
            If m_ThisConfig Is Nothing Then
                m_ThisConfig = Config.Configs.Add("ACOMConfiguration")
            End If
        End Sub

#End Region

#Region " Public Properties "

        ''' <summary>
        ''' The COM port that the ACOM2000A is connected to
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ACOM2000COMPort() As String
            Get
                Return m_ThisConfig.GetString("ACOM2000COMPort", "")
            End Get
            Set(ByVal value As String)
                m_ThisConfig.SetValue("ACOM2000COMPort", value)
            End Set
        End Property

        ''' <summary>
        ''' The method to use for Remote Connections
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property RemoteConnectionMethod() As String
            Get
                Return m_ThisConfig.GetString("RemoteConnectionMethod", "TCP")
            End Get
            Set(ByVal value As String)
                m_ThisConfig.SetValue("RemoteConnectionMethod", value)
            End Set
        End Property

        ''' <summary>
        ''' The current control panel type
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ControlPanelType() As String
            Get
                Return m_ThisConfig.GetString("ControlPanelType", "Large")
            End Get
            Set(ByVal value As String)
                m_ThisConfig.SetValue("ControlPanelType", value)
            End Set
        End Property

        ''' <summary>
        ''' The X location of the large control panel
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LargeControlPanelLocationX() As Integer
            Get
                Return m_ThisConfig.GetInt32("LargeControlPanelLocationX", -1)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("LargeControlPanelLocationX", value)
            End Set
        End Property

        ''' <summary>
        ''' The Y Location of the large control panel
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LargeControlPanelLocationY() As Integer
            Get
                Return m_ThisConfig.GetInt32("LargeControlPanelLocationY", -1)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("LargeControlPanelLocationY", value)
            End Set
        End Property

        ''' <summary>
        ''' The X location of the mini control panel
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property MiniControlPanelLocationX() As Integer
            Get
                Return m_ThisConfig.GetInt32("MiniControlPanelLocationX", -1)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("MiniControlPanelLocationX", value)
            End Set
        End Property

        ''' <summary>
        ''' The Y location of the mini control panel
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property MiniControlPanelLocationY() As Integer
            Get
                Return m_ThisConfig.GetInt32("MiniControlPanelLocationY", -1)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("MiniControlPanelLocationY", value)
            End Set
        End Property

        ''' <summary>
        ''' Should the control panel be shown on startup
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ShowControlPanelOnStartup As Boolean
            Get
                Return m_ThisConfig.GetBoolean("ShowControlPanelOnStartup", False)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("ShowControlPanelOnStartup", value)
            End Set
        End Property

        ''' <summary>
        ''' Should the control panel stay on top of all other windows
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property KeepWindowOnTop As Boolean
            Get
                Return m_ThisConfig.GetBoolean("KeepWindowOnTop", False)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("KeepWindowOnTop", value)
            End Set
        End Property

        ''' <summary>
        ''' Should we use a remote connection
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property UseRemoteConnection As Boolean
            Get
                Return m_ThisConfig.GetBoolean("UseRemoteConnection", False)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("UseRemoteConnection", value)
            End Set
        End Property

        ''' <summary>
        ''' The address of the remote connection
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property RemoteConnectionAddress As String
            Get
                Return m_ThisConfig.GetString("RemoteConnectionAddress", "")
            End Get
            Set(ByVal value As String)
                m_ThisConfig.SetValue("RemoteConnectionAddress", value)
            End Set
        End Property

        ''' <summary>
        ''' Should we allow remote connections to this instance
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property AllowRemoteConnections As Boolean
            Get
                Return m_ThisConfig.GetBoolean("AllowRemoteConnections", False)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("AllowRemoteConnections", value)
            End Set
        End Property

        ''' <summary>
        ''' The port number to use for remote connections
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property RemoteConnectionPort As Integer
            Get
                Return m_ThisConfig.GetInt32("RemoteConnectionPort", 8873)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("RemoteConnectionPort", value)
            End Set
        End Property

        ''' <summary>
        ''' Does the connection to the ACOM2000A support remote power on
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property SupportsRemotePowerOn() As Boolean
            Get
                Return m_ThisConfig.GetBoolean("SupportsRemotePowerOn", True)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("SupportsRemotePowerOn", value)
            End Set
        End Property

        ''' <summary>
        ''' Should we try to determine the operate mode of the ACOM2000A on establishing a connection to it
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property DetermineOperateModeOnConnection() As Boolean
            Get
                Return m_ThisConfig.GetBoolean("DetermineOperateModeOnConnection", False)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("DetermineOperateModeOnConnection", value)
            End Set
        End Property

        ''' <summary>
        ''' The Mechanism used for remote power on
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property RemotePowerOnMechanism() As Integer
            Get
                Return m_ThisConfig.GetInt32("RemotePowerOnMechanism", 2)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("RemotePowerOnMechanism", value)
            End Set
        End Property

        ''' <summary>
        ''' Should we interface with Logger32?
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Logger32InterfaceEnabled() As Boolean
            Get
                Return m_ThisConfig.GetBoolean("Logger32InterfaceEnabled", False)
            End Get
            Set(ByVal value As Boolean)
                m_ThisConfig.SetValue("Logger32InterfaceEnabled", value)
            End Set
        End Property

        ''' <summary>
        ''' Logger32 Radio Number
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Logger32RadioNumber() As Integer
            Get
                Return m_ThisConfig.GetInt32("Logger32RadioNumber", 1)
            End Get
            Set(ByVal value As Integer)
                m_ThisConfig.SetValue("Logger32RadioNumber", value)
            End Set
        End Property

#End Region

#Region " Public Methods "

        ''' <summary>
        ''' Saves the configuration
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Save()
            m_Config.Save()
        End Sub

#End Region

    End Class

End Namespace